package com.android.equipment.dao.operate;

import com.android.equipment.ObjectBox;
import com.android.equipment.dao.People;
import com.android.equipment.dao.People_;

import java.util.List;

import io.objectbox.Box;
import io.objectbox.query.Query;

public class DaoPeople {
    static Box<People> peopleBox;
    private static DaoPeople instance;

    private DaoPeople() {
    }

    public static DaoPeople getInstance() {
        if (instance == null) {
            instance = new DaoPeople();
            peopleBox = ObjectBox.get().boxFor(People.class);
        }
        return instance;
    }

    public void addPeople(People people) {
        peopleBox.put(people);
    }

    public void deletePeople(People people) {
        peopleBox.remove(people);
    }

    public void updatePeople(People people) {
        peopleBox.put(people);
    }

    public People getPeople(long id) {
        return peopleBox.get(id);
    }

    public List<People> getNotDelPeople() {
        Query<People> query = peopleBox.query(People_.isDel.equal(false)).build();
        List<People> peopleList = query.find();
        query.close();
        return peopleList;
    }

    public List<People> getDelPeople() {
        Query<People> query = peopleBox.query(People_.isDel.equal(true)).build();
        List<People> peopleList = query.find();
        query.close();
        return peopleList;
    }

    public List<People> getAllPeople() {
        List<People> peopleList = peopleBox.getAll();
        return peopleList;
    }
}
